package hfuu.com.cn.teasystemapp;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import hfuu.com.cn.teasystemapp.bean.operategz;
import hfuu.com.cn.teasystemapp.bean.operatern;
import hfuu.com.cn.teasystemapp.util.listviewutil;

public class gzlist extends AppCompatActivity {

    private List<HashMap<String, Object>> gzlogdata;
    List<operategz> operategzlist;
    SimpleAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gzlist);
        Intent old=getIntent();
        operategzlist=new ArrayList<operategz>();
        gzlogdata=new ArrayList<HashMap<String, Object>>();
        operategzlist=(List<operategz>) old.getSerializableExtra("gzlist");
        if (operategzlist.size() > 0) {
            for (operategz rn :
                    operategzlist) {
                HashMap<String, Object> item = new HashMap<String, Object>();
                item.put("teaname", rn.getWarehouseteax().getWarehouseTeaname());
                item.put("time", rn.getOperateTotaltime());
                item.put("wd1",rn.getOperateWd1());
                item.put("wd2",rn.getOperateWd2());
                item.put("isfocus", false);
                gzlogdata.add(item);
            }
            ListView sqloglist = (ListView) findViewById(R.id.gzloglist);
            ImageView back = (ImageView) findViewById(R.id.back);
            back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
            Log.i("wd",gzlogdata.toString());
            adapter = new SimpleAdapter(this, gzlogdata, R.layout.gzlogitem, new String[]{"teaname", "wd1","wd2"}, new int[]{R.id.teaname, R.id.wd1,R.id.wd2}) {
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View view = super.getView(position, convertView, parent);
                    Boolean isFocus = (Boolean) gzlogdata.get(position).get("isfocus");

                    if (isFocus) {
                        view.setBackgroundColor(getResources().getColor(R.color.tv_gray));
                    } else {
                        view.setBackgroundColor(Color.WHITE);
                    }
                    return view;
                }
            };
            sqloglist.setAdapter(adapter);
            listviewutil.setListViewHeightBasedOnChildren(sqloglist);
        }
    }
}
